-- enough_spell
-- created by panyl
-- 卷轴是否足够问题

return {
    fetch = function(id)
        return true;
    end,

    calc_bonus = function(id)
        local args = PinocchioM.query_quetion(id, "bonus_args") or {};

        return { 1, args["item"], args["count"] or 1, };
    end,

    check_answer = function(id, index)
        local cond = PinocchioM.query_quetion(id, "condition");

        if type(cond) ~= "number" or cond <= 0 then
            return 1;
        end

            -- 卷轴
        local allSpells = ItemM.getItemsByType(ME.user, ITEM_TYPE_SPELL);
        local spell_num = 0;
        for _, classId in pairs(allSpells) do
            spell_num = spell_num + ItemM.getAmount(ME.user, classId);
        end

        -- 是否选择了正确的选项
        local res = iif(spell_num >= cond, 1, 2);

        return iif(res == index, 1, 0);
    end,
};
